<?php

namespace lc\wechat\auth;

use think\exception\ClassNotFoundException;

/**
 * @desc
 * @method  static \lc\wechat\auth\Gateways\General     General
 * @method  static \lc\wechat\auth\Gateways\Platform    Platform
 * @method  static \lc\wechat\auth\Gateways\Mini        Mini
 * @package lc\wechat\auth
 * @author  TY
 */
class WeChat
{
    /**
     * @param   string  $method
     * @return  Service
     */
    private static function make($method)
    {
        $value = ucwords(str_replace(['-', '_'], ' ', $method));

        $gateway = __NAMESPACE__ . '\\Gateways\\' . $value;

        if (class_exists($gateway)) {
            return new $gateway();
        }

        throw new ClassNotFoundException("Gateway [{$method}] Not Exists");
    }

    /**
     * @desc
     * @param   string  $method
     * @param   array   $arguments
     * @return  mixed
     */
    public static function __callStatic($method, $arguments)
    {
        return self::make($method, ...$arguments);
    }
}